﻿using System;
using AumationTest;
using OpenQA.Selenium;
using NPMonitor.Attributes;
using NPMonitor.DataModel;
using NPMonitor.Utility;
using System.Threading;

namespace SampleJob
{
    [Serializable]
    public class SMSJob : WebJobBase
    {
        protected override void ExecuteJob(HttpWatch.Plugin plugin)
        {
            //metaData = metaData ?? "" + System.Guid.NewGuid().ToString();

            //Logger.Debug("Starting TimingJob - " + metaData);

            Senario1();

            //Logger.Debug("TimingJob - " + metaData + " Finished");

            ExecutionResult.ErrorMessage = string.Empty;
            ExecutionResult.ResultStatus = JobResultStatus.Success;
        }

        #region Secnarios

        [Scenario("SJ_SMS_001", "Sample SMS Job 001", "SMS Test Sample Job 001", null)]
        public void Senario1()
        {
            string fakename = Faker.Name.FullName();
            string fakenumbers = Faker.Phone.Number();
            string fakegroupname = Faker.Address.StreetName();
            int sleepTime = 5000;
            JobExecutionResult result = new JobExecutionResult();

            var browser = new AutomationTestBase(WebDriver);

            browser.GoToUrl("http://ws-dc-01:8082");

            //// Infinite running job
            //while (true)
            //{
            //    Thread.Sleep(1000);
            //}

            System.Threading.Thread.Sleep(sleepTime);
            AutomationOperation.InputTextControlByID(browser, "InputUserName", "dada liao");
            AutomationOperation.InputTextControlByID(browser, "InputPassword", "12");
            AutomationOperation.ControlClickByID(browser, "SubmitButton");
            System.Threading.Thread.Sleep(sleepTime);

            var loginbar = WebDriver.FindElement(By.ClassName("settings"));
            var btnLogin = loginbar.FindElements(By.TagName("a"))[1];
            btnLogin.Click();

            System.Threading.Thread.Sleep(sleepTime);
            //Logger.Debug("Current domain is " + AppDomain.CurrentDomain.FriendlyName);

            //browser.TearDown();
        }

        #endregion
    }
}
